﻿@model BLL.ComplexClasses.User
@{
    ViewBag.heading1 = "Users";
    ViewBag.heading2 = "List";
    ViewBag.Title = "Users List";
    Layout = "~/Views/Shared/_Layout.cshtml";    
}
@section Scripts {
    <script type="text/javascript" language="javascript">
    $(document).ready(function () {
    var user_type="Admin";
    BindServerDatatable('#tblUsers',"@Url.Action("LoadUsersList", "Users")",[
                        { "sTitle": "Name",
                            
                            "bSearchable": true,
                            "bSortable": true,
                            "mData": 'first_name',
                            "fnRender": function (oObj) {
                                return oObj.aData.first_name+ ' ' + oObj.aData.last_name;                                
                            }
                        }, { "sTitle": "Login Id", "mData": "login_id" },
                         { "sTitle": "View", "mData": null, "fnRender": function (oObj) {
                            //return "";
                                //return oObj.aData.salutation+ ' '+ oObj.aData.first_name+ ' ' + oObj.aData.last_name;
                                return '<a href="javascript:void(0)" class="edit" onclick="addEditUser(this);" user_id = "' + oObj.aData.user_id + '\"><i class="icon icon-edit tip-top" title="Edit"></i></a>';
                            }
                         },
                         { "sTitle": "Delete", "mData": null, "fnRender": function (oObj) {
                                //return oObj.aData.salutation+ ' '+ oObj.aData.first_name+ ' ' + oObj.aData.last_name;
                                //return "";
                                return '<a href="javascript:void(0)" class="delete" user_id = "/' + oObj.aData.user_id + '\"><i class="icon icon-remove tip-top" title="Delete"></i></a>';
                            }}
                    ],JSON.stringify(user_type)); 
    
    
    $("#btnSave").click(function(){     
       
        var Data = JSON.stringify({
            first_name : $("#first_name").val(),
            last_name : $("#last_name").val(),
            login_id : $("#login_id").val(),
            password : $("#password").val()    
        });
        
        var result = AjaxCallWithData("@Url.Action("Save", "Users")", Data);

        if(result.Result == "OK")
        {
            $("#dvAddUser").modal("hide");
            $("#first_name").val("");
            $("#last_name").val("");
            $("#login_id").val("");
            $("#password").val(""); 
            $("#dvSuccess").removeClass("hide");
        }
        else
        {
            $("#dvError").removeClass("hide");
        }
    });
    
    
    });

    


    </script>
}
<div class="row-fluid">
    <div class="span12">
        <div class="head clearfix">
            <div class="isw-users">
            </div>
            <h1>
                @ViewBag.Title</h1>
            <ul class="buttons">
                <li><a href="#dvAddUser" role="button" data-toggle="modal" class="isw-plus"></a>
                </li>
            </ul>
        </div>
        <div id="dvSuccess" class="alert alert-success hide">
            <h4>
                Success!</h4>
            User Saved succesfully.
        </div>
        <div class="block-fluid table-sorting clearfix">
            <table cellpadding="0" cellspacing="0" width="100%" class="table" id="tblUsers">
            </table>
        </div>
    </div>
</div>
<div class="dr">
    <span></span>
</div>
<div id="dvAddUser" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
    aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
            ×</button>
        <h3 id="myModalLabel">
            Add User</h3>
    </div>
    <div class="row-fluid">
    <div id="dvError" class="alert alert-error hide">                
                    <h4>Error!</h4>
                    Hey, you have some error here... 
                </div>  
        <div class="block-fluid">
            <div class="row-form clearfix">
                <div class="span3">
                    First Name:
                </div>
                <div class="span9">
                    @Html.TextBoxFor(model => model.first_name)</div>
            </div>
            <div class="row-form clearfix">
                <div class="span3">
                    Last Name:</div>
                <div class="span9">
                    @Html.TextBoxFor(model => model.last_name)</div>
            </div>
            <div class="row-form clearfix">
                <div class="span3">
                    Login Id:</div>
                <div class="span9">
                    @Html.TextBoxFor(model => model.login_id)</div>
            </div>
            <div class="row-form clearfix">
                <div class="span3">
                    Passowrd:</div>
                <div class="span9">
                    @Html.TextBoxFor(model => model.password)</div>
            </div>
        </div>
        <div class="dr">
            <span></span>
        </div>
    </div>
    <div class="modal-footer">
        @*<button class="btn">
            Send</button>*@
        <button class="btn btn-warning" id="btnSave">
            Save</button>
        <button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">
            Close</button>
    </div>
</div>
